package com.eric;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MysqlConfig {

	static Connection con = null;
	static String base = "jdbc:mysql://120.25.87.76:3306/";
	static String user = "root";// user name for the specified database
	static String pwd = "wih486eev";// the corresponding password ";
	static String db = "crawl";
	static String table = "indie_sites";
	static String enc = "?characterEncoding=utf8";

	static String sql = "";

	public static void setHost(String host) {
		base = "jdbc:mysql://" + host + ":3306/";
	}

	public static void setUser(String user) {
		MysqlConfig.user = user;
	}

	public static void setPass(String pass) {
		MysqlConfig.pwd = pass;
	}

	public static void setDB(String dbName) {
		MysqlConfig.db = dbName;
	}

	public static ResultSet executeSql(String sql) {
		try {
			Statement stmt = con.createStatement();
			return stmt.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Connection connect() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url = base + db + enc;
			con = DriverManager.getConnection(url, user, pwd);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

}
